#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#include "MSTK.h"
#include <mpi.h>

int main(int argc, char *argv[]) {
  int  i, dim, num, rank;
  char mname[256],filename[256];


  if(argc == 1) {
    printf("a parallel example code\n");
    printf("usage: mpirun -np %s 4 meshname -d 2\n",argv[0]);
    exit(-1);
  }
  
  /* Initialize MSTK */
  MSTK_Init();  
  /* initialize MPI */
  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD,&num);
  MPI_Comm_rank(MPI_COMM_WORLD,&rank);

  /* Load the mesh */
  strcpy(mname,argv[1]);
  strcpy(filename,mname);
  strcat(filename,".mstk");
  dim = atoi(argv[3]);
  
  /* each processor gets the sub mesh */
  Mesh_ptr mesh = MESH_New(UNKNOWN_REP);
  MSTK_Mesh_Scatter(&mesh, filename, dim, 1, 1, rank, num, MPI_COMM_WORLD);


  /* do some operation on mesh */
  
  /* update ghost attribute values */
  MSTK_UpdateAttr(mesh,rank,num,MPI_COMM_WORLD);


  /* finish MPI */
  MPI_Finalize();
  return 1;
}

